package com.hxd.otc.module.my.adapter;

import android.content.Context;
import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.text.TextPaint;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.hxd.otc.R;
import com.hxd.otc.base.BaseAdapter;
import com.hxd.otc.common.enums.NoticeType;
import com.hxd.otc.module.my.bean.NoticeBean;
import com.hxd.otc.utils.DateUtil;
import com.hxd.otc.utils.ResourceUtil;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * Created by lzy on 2018/6/15 0015.
 * description ${消息列表 Adapter}
 */
public class AfficheAdapter extends BaseAdapter<AfficheAdapter.AfficheViewHolder, NoticeBean> {

    public AfficheAdapter(Context context) {
        super(context);
    }

    @Override
    protected void onBindHolder(@NonNull AfficheViewHolder holder, int position) {
        NoticeBean item = getItem(position);
        NoticeType noticeType = item.getNoticeType();
        holder.ivMessage.setImageResource(item.isLook() ? noticeType.getReadResId() : noticeType.getUnReadResId());
        holder.tvTitle.setText(item.getTitle());
        TextPaint tp = holder.tvTitle.getPaint();
        tp.setFakeBoldText(!item.isLook());
        holder.tvTitle.setTextColor(ResourceUtil.getColor(item.isLook() ? R.color.color_FFB1B1B1 : R.color.color_EditText_text));
        holder.ivRed.setVisibility(item.isLook() ? View.GONE : View.VISIBLE);
        holder.tvDate.setText(DateUtil.formatMessageTime(item.getCreateTime()));
    }

    @NonNull
    @Override
    public AfficheViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        return new AfficheViewHolder(mInflater.inflate(R.layout.item_affiche, parent, false));
    }

    static class AfficheViewHolder extends RecyclerView.ViewHolder {
        @BindView(R.id.iv_message)
        ImageView ivMessage;
        @BindView(R.id.tv_title)
        TextView tvTitle;
        @BindView(R.id.tv_date)
        TextView tvDate;
        @BindView(R.id.iv_red)
        ImageView ivRed;

        AfficheViewHolder(View itemView) {
            super(itemView);
            ButterKnife.bind(this, itemView);
        }
    }

}
